﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace Agresso.Interface.Layer.Domain
{
    public class BunkerGRN
    {
        public string vessel_name = string.Empty;
        public string voyage_no = string.Empty;
        public DateTime stemmed_date = DateTime.Today;
        public string supplier = string.Empty;
        public int enquiry_no = 0;
        public string lifting_status = string.Empty;
        public string grade = string.Empty;
        public GradeAccountMapping GradeAccountMapping = null;
        public decimal quantity_delivered = 0;
        public DateTime delivery_Date = DateTime.Today;
        public DateTime enquiry_Date = DateTime.Today;

        public int i_bunkergrn_id = 0;
        public string pickup_flag = string.Empty;
        public DateTime pickup_date = new DateTime(1900, 1, 1);
        public DateTime pickup_update_date = new DateTime(1900, 1, 1);
        public DateTime insert_date = new DateTime(1900, 1, 1);
        public string remarks = ""; //header detail
        public string batch_id = "";

        public BunkerGRN(int enqNumber, string grd)
        {
            enquiry_no = enqNumber;
            grade = grd;
        }
        public BunkerGRN(SqlDataReader rd)
        {
            enquiry_no = rd["enquiry_no"] is DBNull ? enquiry_no : Convert.ToInt32(rd["enquiry_no"]);
            enquiry_Date = rd["enquiry_date"] is DBNull ? new DateTime(1900, 1, 1) : Convert.ToDateTime(rd["enquiry_date"]);
            pickup_date = rd["pickup_date"] is DBNull ? new DateTime(1900, 1, 1) : Convert.ToDateTime(rd["pickup_date"]);
            remarks = rd["remarks"] is DBNull ? "" : rd["remarks"].ToString();
        }
        public BunkerGRN(SqlDataReader rd, bool frominterface)
        {
            vessel_name = rd["vessel_name"] is DBNull ? "" : rd["vessel_name"].ToString();
            voyage_no = rd["voyage_no"] is DBNull ? "" : rd["voyage_no"].ToString();
            stemmed_date = rd["stemmed_date"] is DBNull ? new DateTime(2000, 1, 1) : Convert.ToDateTime(rd["stemmed_date"]);
            supplier = rd["supplier"] is DBNull ? "" : rd["supplier"].ToString();
            enquiry_no = rd["enquiry_no"] is DBNull ? 0 : Convert.ToInt32(rd["enquiry_no"]);
            lifting_status = rd["lifting_status"] is DBNull ? "" : rd["lifting_status"].ToString();
            grade = rd["grade"] is DBNull ? "" : rd["grade"].ToString();
            quantity_delivered = rd["quantity_delivered"] is DBNull ? 0 : Convert.ToDecimal(rd["quantity_delivered"]);
            delivery_Date = rd["delivery_Date"] is DBNull ? new DateTime(2000, 1, 1) : Convert.ToDateTime(rd["delivery_Date"]);
            enquiry_Date = rd["enquiry_Date"] is DBNull ? new DateTime(2000, 1, 1) : Convert.ToDateTime(rd["enquiry_Date"]);
            if (frominterface)
            {
                pickup_flag = rd["pickup_flag"] is DBNull ? "" : rd["pickup_flag"].ToString();
                pickup_date = rd["pickup_date"] is DBNull ? new DateTime(2000, 1, 1) : Convert.ToDateTime(rd["pickup_date"]);
                pickup_update_date = rd["pickup_update_date"] is DBNull ? new DateTime(2000, 1, 1) : Convert.ToDateTime(rd["pickup_update_date"]);
                insert_date = rd["insert_date"] is DBNull ? new DateTime(2000, 1, 1) : Convert.ToDateTime(rd["insert_date"]);
                i_bunkergrn_id = rd["i_bunkergrn_id"] is DBNull ? 0 : Convert.ToInt32(rd["i_bunkergrn_id"]);
                remarks = rd["remarks"] is DBNull ? "" : rd["remarks"].ToString();
                batch_id = rd["batch_id"] is DBNull ? "" : rd["batch_id"].ToString();
            }
        }
        public override bool Equals(object obj)
        {
            if (!(obj is BunkerGRN))
                return false;
            BunkerGRN bg = (BunkerGRN)obj;
            bool a = enquiry_no == bg.enquiry_no;
            bool b = grade == bg.grade;
            return a && b;
        }
       
    }
}
